<?php

class ServiceCentersTabs extends CWidget {

    public $brandUrl = 0;

    public function run() {
        $cats = array();
        $brands2 = array();
        $brands = array();
        $values = json_decode($this->brandUrl, true);
        if (!empty($values)):
            $values = implode(',', $values);
            $c = new CDbCriteria();
            $c->select = '"pageTitle", "pageUrl"';
            $c->addCondition('"pageId" IN(' . $values . ') AND "pageType" = \'brand\'');
            //$c->addInCondition('"pageId"', $values);
            $brands = Page::model()->findAll('"pageId" IN(' . $values . ') AND "pageType" = \'brand\'');
            foreach ($brands as $b) {
                $brands2[$b['pageParent']] = array('pageId' => $b['pageId'], 'pageUrl' => $b['pageUrl']);
            }

            $catIDS = CHtml::listData($brands, 'pageParent', 'pageParent');
            $catIDS = implode(',', $catIDS);
            if (!empty($catIDS)) {
                $sql = "SELECT \"pageTitle\", \"pageId\", \"pageUrl\" FROM {{pages}} WHERE \"pageId\" IN($catIDS) ORDER BY \"pageSort\"";
                $cats = Yii::app()->db->getCommandBuilder()->createSqlCommand($sql)->queryAll();
            } else {
                $cats = array();
            }
        endif;
//        print_r($brands);exit;
        $this->render('serviceTabs', array('cats' => $cats, 'brands' => $brands2, 'brands1' => $brands));
    }

}
